<?php

namespace app\admin\model\air;

use think\Model;


class Setting extends Model
{

    

    

    // 表名
    protected $name = 'air_setting';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
    

    static public function getOneSetting($name)
    {
        $data = self::where('name', $name)->find();
        return $data->value;
    }
    
    static public function getSettings()
    {
        $allData = self::select(); 
        $data = [];
        foreach ($allData as $d) {
            $data[$d['name']] = $d['value'];
        }

        return $data;
    }

    static public function getSingleSetting($name, $allSettings = [])
    {
        if (empty($allSettings)) {
            $allSettings = self::getSettings();
        }
        if (empty($allSettings)) {
            return '';
        }
        if (!isset($allSettings[$name])) {
            return '';
        }
        return $allSettings[$name];
    }







}
